<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Auction
 * @version 	: 1.1
 * COPYRIGHT    : 2010
 * ------------------------------------------------------
 *
 * Created on	:  Sep 13, 2010
 *
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RClassesImporter::cls('controllers.AbstractBackEndController');

/**
 * The controller for State application
 *
 */
class VideoFrontController extends AbstractBackEndController {

	var $_model;

	function __construct() {
		parent::__construct();
		SysApplication::importModelCls('VideoModel');
		$this->_model = new VideoModel();
	}

	function display() {
		$root = SYS_ROOT_URL;
		$model = $this->_model;
		//$ypage = SysRequest::getVar('vpage', 1);
		$lang = $_REQUEST['lang'];

		$photo = SysLanguage::_("PHOTO");
		$video = SysLanguage::_("VIDEO");
		$presentation = SysLanguage::_("PRESENTATION");
		
		$limit = 4;
		$ypage = SysRequest::getVar('vpage', 1);
		$videos = $model->getVideoPaging($ypage, $limit);
		$videoItems = $videos->getRecordSet();
		$videoList = "";
		$num = 0;
		foreach ($videoItems as $item){
			$num ++;
			$id = $item->video_id;
			$videoLink = $item->link;
			$link = explode('?', $videoLink);
			$link2 = explode('/', $link[0]);
			$link1 = explode('=', $link[1]);
			$newLink = implode('/', array($link2[0], '', $link2[2], $link1[0], $link1[1]));
			$newLink .= '?fs=1&amp;hl=en_US&amp;showinfo=0&amp;showsearch=0&amp;rel=0';
			if($_REQUEST['lang'] == 'fr'){
				$des = strip_tags($item->des_fr);
			} else if($_REQUEST['lang'] == 'en'){
				$des = strip_tags($item->des_en);
			}
			
			if (strlen($des) > 100){
				$des = substr($des, 0, 100)."...";
			}
			eval('$videoList .= "'.SysApplication::loadTemplate('front/videoItem').'";');
		}


		$pagerVideo = SysTemplate::getPaginationInstance($videos->getTotalRecords(), $limit, "?vpage");
		$pagerVideo->setPagerText('<<','<','>','>>');
		$pagingVideoHtml = $pagerVideo->renderPager($ypage);

		//Load title------------
		$sql = "SELECT * FROM title WHERE id=4";
		$resultTitle = SysDatabase::loadObject($sql);
		if($_REQUEST['lang'] == 'fr'){
			$title = $resultTitle->title_fr;
		} else if($_REQUEST['lang'] == 'en'){
			$title = $resultTitle->title_en;
		}
		eval('echo "'.SysApplication::loadTemplate('front/default').'";');

	}
	function details() {
		$root = SYS_ROOT_URL;
		$model = $this->_model;
		$id = SysRequest::getVar('task');
		$result = $model->loadVideoDetail($id);
		$image = $result->image;
		$title = $result->title;
		$content = $result->content;
		$service_id = $result->service_id;

		eval('echo "'.SysApplication::loadTemplate('front/serviceDetails').'";');
	}


}
